<!DOCTYPE HTML PUBLIC "-//ORA//DTD CD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>[Chapter 29] The java.text Package</TITLE>
<META NAME="author" CONTENT="David Flanagan">
<META NAME="date" CONTENT="Thu Jul 31 16:32:50 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java">
<META NAME="title" CONTENT="Java in a Nutshell">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">
<script language='JavaScript'>
<!--
if (location.replace) {
 location.replace ('ch29_js.htm');
}
// -->
</script>

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java in a Nutshell" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch28_26.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 29</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch29_02.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<H1 CLASS=chapter><A CLASS="TITLE" NAME="JNUT2-CH-29">29. The java.text Package</A></H1>

<DIV CLASS=htmltoc>

<p>
<b>Contents:</b><br>
<a href='ch29_02.htm'>java.text.CharacterIterator (JDK 1.1)</a><br>
<a href='ch29_03.htm'>java.text.ChoiceFormat (JDK 1.1)</a><br>
<a href='ch29_04.htm'>java.text.CollationElementIterator (JDK 1.1)</a><br>
<a href='ch29_05.htm'>java.text.CollationKey (JDK 1.1)</a><br>
<a href='ch29_06.htm'>java.text.Collator (JDK 1.1)</a><br>
<a href='ch29_07.htm'>java.text.DateFormat (JDK 1.1)</a><br>
<a href='ch29_08.htm'>java.text.DateFormatSymbols (JDK 1.1)</a><br>
<a href='ch29_09.htm'>java.text.DecimalFormat (JDK 1.1)</a><br>
<a href='ch29_10.htm'>java.text.DecimalFormatSymbols (JDK 1.1)</a><br>
<a href='ch29_11.htm'>java.text.FieldPosition (JDK 1.1)</a><br>
<a href='ch29_12.htm'>java.text.Format (JDK 1.1)</a><br>
<a href='ch29_13.htm'>java.text.MessageFormat (JDK 1.1)</a><br>
<a href='ch29_14.htm'>java.text.NumberFormat (JDK 1.1)</a><br>
<a href='ch29_15.htm'>java.text.ParseException (JDK 1.1)</a><br>
<a href='ch29_16.htm'>java.text.ParsePosition (JDK 1.1)</a><br>
<a href='ch29_17.htm'>java.text.RuleBasedCollator (JDK 1.1)</a><br>
<a href='ch29_18.htm'>java.text.SimpleDateFormat (JDK 1.1)</a><br>
<a href='ch29_19.htm'>java.text.StringCharacterIterator (JDK 1.1)</a><br>
<p>
<p>
</DIV>

<P CLASS=para>
The <tt CLASS=literal>java.text</tt> package consists of classes and
interfaces that are useful for writing internationalized programs
that handle local customs, such as date and time formatting
and string alphabetization, correctly.  This package is  new
in Java 1.1.<A NAME="CH29.JAVA.TEXT.PA1"></A>
<A HREF="ch29_01.htm#JNUT2-CH-29-FIG-1">Figure 29.1</A>
shows its class hierarchy.

<P CLASS=para>
The <tt CLASS=literal>NumberFormat</tt> class formats numbers, monetary
quantities, and percentages as appropriate for the default
or specified locale.  <tt CLASS=literal>DateFormat</tt> formats dates and
times in a locale-specific way.  The concrete
<tt CLASS=literal>DecimalFormat</tt> and <tt CLASS=literal>SimpleDateFormat</tt>
subclasses of these classes can be used for customized
number, date, and time formatting.  <tt CLASS=literal>MessageFormat</tt>
allows substitution of dynamic values, including formatted
numbers and dates, into static message strings.
<tt CLASS=literal>ChoiceFormat</tt> formats a number using an enumerated
set of string values.  <tt CLASS=literal>Collator</tt> compares strings
according to the customary sorting order for a locale.
<tt CLASS=literal>BreakIterator</tt> scans text to find word, line, and
sentence boundaries following locale-specfic rules.

<DIV CLASS=figure>
<h4 CLASS=figure><A CLASS="TITLE" NAME="JNUT2-CH-29-FIG-1">Figure 29.1: The java.text package</A></h4>


<p>
<img align=middle src="./figs/jn2_2901.gif" alt="[Graphic: Figure 29-1]" width=464 height=414 border=0>

</DIV>

<DIV CLASS=sect1>
<h2 CLASS=sect1><A CLASS="TITLE" NAME="JNUT2-CH-29-SECT-1">29.1 java.text.BreakIterator (JDK 1.1)</A></h2>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-29-SECT-1.1"></A></h3>
</DIV>

<P CLASS=para>
This class is used to determine character, word, sentence,
and line breaks in a block of text in a way that is
independent of locale and text-encoding.  As an abstract
class, <tt CLASS=literal>BreakIterator</tt> cannot be instantiated
directly.  Instead, you must use one of the class methods
<tt CLASS=literal>getCharacterInstance()</tt>, <tt CLASS=literal>getWordInstance()</tt>,
<tt CLASS=literal>getSentenceInstance()</tt>, or <tt CLASS=literal>getLineInstance()</tt> to
return an instance of a nonabstract subclass of
<tt CLASS=literal>BreakIterator</tt>.  These various "factory" methods
return a <tt CLASS=literal>BreakIterator</tt> object that is configured to
locate the requested boundary types, and is localized to
work for the optionally specified locale.

<P CLASS=para>
Once you have obtained an appropriate <tt CLASS=literal>BreakIterator</tt>
object, you use <tt CLASS=literal>setText()</tt> to specify the text that
it is to locate boundaries in.  To locate boundaries in a Java
<tt CLASS=literal>String</tt> object, simply specify the string.  To locate
boundaries in text that uses some other encoding, you must
specify a <tt CLASS=literal>CharacterIterator</tt> object for that text so
that the <tt CLASS=literal>BreakIterator</tt> object can locate the
individual characters of the text.

<P CLASS=para>
Having set the text to be searched, you can determine the
character positions of characters, words, sentences, or line
breaks with the <tt CLASS=literal>first()</tt>, <tt CLASS=literal>last()</tt>,
<tt CLASS=literal>next()</tt>, <tt CLASS=literal>previous()</tt>, <tt CLASS=literal>current()</tt>, and
<tt CLASS=literal>following()</tt> methods, which perform the obvious functions.
Note that these methods do not return text itself, but
merely the position of the appropriate word,
sentence, or line break.

<DIV CLASS=screen>
<P>
<PRE>
public abstract class <tt CLASS=literal>BreakIterator</tt> extends Object implements Cloneable, Serializable {
    // <tt CLASS=literal>Protected Constructor</tt>
            protected <tt CLASS=literal>BreakIterator</tt>();
    // <tt CLASS=literal>Constants</tt>
            public static final int <tt CLASS=literal>DONE</tt>;
    // <tt CLASS=literal>Class Methods</tt>
            public static synchronized Locale[] <tt CLASS=literal>getAvailableLocales</tt>();
            public static BreakIterator <tt CLASS=literal>getCharacterInstance</tt>();
            public static BreakIterator <tt CLASS=literal>getCharacterInstance</tt>(Locale <tt CLASS=literal>where</tt>);
            public static BreakIterator <tt CLASS=literal>getLineInstance</tt>();
            public static BreakIterator <tt CLASS=literal>getLineInstance</tt>(Locale <tt CLASS=literal>where</tt>);
            public static BreakIterator <tt CLASS=literal>getSentenceInstance</tt>();
            public static BreakIterator <tt CLASS=literal>getSentenceInstance</tt>(Locale <tt CLASS=literal>where</tt>);
            public static BreakIterator <tt CLASS=literal>getWordInstance</tt>();
            public static BreakIterator <tt CLASS=literal>getWordInstance</tt>(Locale <tt CLASS=literal>where</tt>);
    // <tt CLASS=literal>Public Instance Methods</tt>
            public Object <tt CLASS=literal>clone</tt>();  //<tt CLASS=literal> Overrides Object</tt>
            public abstract int <tt CLASS=literal>current</tt>();
            public abstract int <tt CLASS=literal>first</tt>();
            public abstract int <tt CLASS=literal>following</tt>(int <tt CLASS=literal>offset</tt>);
            public abstract CharacterIterator <tt CLASS=literal>getText</tt>();
            public abstract int <tt CLASS=literal>last</tt>();
            public abstract int <tt CLASS=literal>next</tt>(int <tt CLASS=literal>n</tt>);
            public abstract int <tt CLASS=literal>next</tt>();
            public abstract int <tt CLASS=literal>previous</tt>();
            public void <tt CLASS=literal>setText</tt>(String <tt CLASS=literal>newText</tt>);
            public abstract void <tt CLASS=literal>setText</tt>(CharacterIterator <tt CLASS=literal>newText</tt>);
}
</PRE>
</DIV>

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-29-SECT-1.2">Returned By:</A></h3>

<P CLASS=para>
BreakIterator.getCharacterInstance(), 
BreakIterator.getLineInstance(), 
BreakIterator.getSentenceInstance(), 
BreakIterator.getWordInstance()

</DIV>

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch28_26.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch29_02.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>java.net.URLStreamHandlerFactory (JDK 1.0)</td>
<td width=171 align=center valign=top><a href="index/idx_0.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>java.text.CharacterIterator (JDK 1.1)</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
